package utils

import (
	"github.com/cloudwego/hertz/pkg/app"
	hertz "github.com/cloudwego/hertz/pkg/common/utils"
	"github.com/cloudwego/hertz/pkg/protocol/consts"
)

const (
	ResultCodeSystemError = 99 // 系统级别错误
	ResultCodeAuth        = 2  // 权限错误
	ResultCodeError       = 1  // 常用错误
	ResultCodeSuccess     = 0  // 成功
)

func ResultSuccessMsg(rc *app.RequestContext, msg string) {
	rc.JSON(consts.StatusOK, hertz.H{"errno": ResultCodeSuccess, "errmsg": msg, "data": nil})
}

func ResultSuccessData(rc *app.RequestContext, data interface{}) {
	rc.JSON(consts.StatusOK, hertz.H{"errno": ResultCodeSuccess, "errmsg": "", "data": data})
}
func ResultSuccess(rc *app.RequestContext, msg string, data interface{}) {
	rc.JSON(consts.StatusOK, hertz.H{"errno": ResultCodeSuccess, "errmsg": msg, "data": data})
}

func ResultSystemError(rc *app.RequestContext, errMsg string) {
	rc.JSON(consts.StatusOK, hertz.H{"errno": ResultCodeSystemError, "errmsg": errMsg, "data": nil})
}

func ResultError(rc *app.RequestContext, errMsg string) {
	rc.JSON(consts.StatusOK, hertz.H{"errno": ResultCodeError, "errmsg": errMsg, "data": nil})
}

func ResultErrorData(rc *app.RequestContext, errMsg string, data interface{}) {
	rc.JSON(consts.StatusOK, hertz.H{"errno": ResultCodeError, "errmsg": errMsg, "data": data})
}

func ResultAuthError(rc *app.RequestContext) {
	rc.JSON(consts.StatusOK, hertz.H{"errno": ResultCodeAuth, "errmsg": "登录已失效", "data": nil})
}

func Result(rc *app.RequestContext, errno int, errmsg string, data interface{}) {
	rc.JSON(consts.StatusOK, hertz.H{"errno": errno, "errmsg": errmsg, "data": data})
}
